<template>
  <view class="box_content">
    <view
      :style="{
        color: 'rgb(173, 173, 173)',
        'text-align': 'center',
        padding: '0 30rpx',
        'margin-top': '40rpx',
      }"
      v-if="showAnTitle"
      >{{ anTitle }}</view
    >
    <view class="box_content1" v-for="(item, index) in listv" :key="index">
      <view>
        <view class="title" v-if="item.user">
          <!-- 头像 -->
          <image
            :src="item.user.avatar_url"
            @click.stop="toHome(item.user_id)"
          ></image>
          <!-- 名称，发布时间 -->
          <view class="right">
            <view class="name">{{ item.user.nick_name }}</view>
            <view class="gangg">{{ item.create_time }}</view>
          </view>
          <!-- 单选按钮 -->
          <view
            class="click_view"
            @click.stop="changeClickItem(item)"
            v-show="!flag"
          >
            <image
              v-if="!item.clickable"
              src="../static/images/my/icon_grzy_quanxuan.png"
              mode=""
            ></image>
            <image
              v-else
              src="../static/images/my/icon_grzy_xc_xuanzhong.png"
              mode=""
            ></image>
          </view>
        </view>
        <!-- {{my_level_id}}
        {{item.grade_auth}} -->
        <!-- 预览样式 -->
        <!-- <view class="Preview_style" v-if="my_level_id < item.grade_auth  && item.msg!='此作品已删除'" @click.stop="goMember">
          该内容仅支持{{
            item.grade_auth == 1
              ? "元气驿站"
              : item.grade_auth == 2
              ? "启初梦谷"
              : item.grade_auth == 3
              ? "青空天台"
              : item.grade_auth == 4
              ? "无极云顶"
              : item.grade_auth == 5
              ? "返朴归源"
              : ""
          }}及以上行者查看
        </view> -->

        <!-- 非预览样式 -->
        <view class="all_detail">
          <!-- 内容 -->
          <view
            class="box_details"
            @click.stop="goPage(item)"
            :class="my_level_id < item.grade_auth ? 'box_details1' : ''"
          >
            {{ item.content || item.msg }}
          </view>

          <view v-if="my_level_id >= item.grade_auth">
            <!-- 图片 -->
            <view
              class="jiugong"
              :class="
                item.file.length == 1
                  ? 'jiugong1'
                  : item.file.length == 4
                  ? 'jiugong4'
                  : ''
              "
              v-if="item.file && item.file.length > 1"
            >
              <view
                class="jiugong_img"
                v-for="(itemValue, index) in item.file"
                :key="index"
                @click.stop="goPreview(itemValue, item.file)"
              >
                <!-- 图片展示图 -->
                <image
                  :src="itemValue.url"
                  v-if="itemValue.file_type == 10"
                ></image>
                <!-- 视频展示图 -->
                <image
                  :src="itemValue.url_img"
                  v-if="itemValue.file_type == 30"
                ></image>
                <!-- 遮罩层 -->
                <view class="jiugong_img_mask" v-if="itemValue.file_type == 30">
                  <view class="video_cover_play">
                    <image src="@/static/images/icon_dtym_bofang.png"></image>
                  </view>
                </view>
              </view>
            </view>
            <!-- 长图 -->
            <view
              class="long_img"
              v-if="
                item.file &&
                item.file.length == 1 &&
                item.file[0].file_type == 10
              "
            >
              <image
                :src="item.file[0].url"
                mode="widthFix"
                @click.stop="goPreview(item.file[0], item.file)"
              ></image>
            </view>
            <!-- 单视频 -->
            <view
              class="single_video"
              v-if="
                item.file &&
                item.file.length == 1 &&
                item.file[0].file_type == 30
              "
              @click.stop="goPreview(item.file[0], item.file)"
            >
              <!-- <video id="myVideo" :src="item.file[0].url" controls :poster="item.file[0].url_img"></video> -->
              <image :src="item.file[0].url_img" mode="widthFix"></image>
              <!-- 遮罩层 -->
              <view class="jiugong_img_mask">
                <view class="video_cover_play">
                  <image src="@/static/images/icon_dtym_bofang.png"></image>
                </view>
              </view>
            </view>
            <!-- 录音 -->
            <view class="sound" v-if="hasSound">
              <progressBar way="1"></progressBar>
            </view>
          </view>

          <view
            class="card_content_box_preview"
            v-if="my_level_id < item.grade_auth"
            @click.stop="goMember"
          >
            该内容仅支持{{
              item.grade_auth == 1
                ? "元气驿站"
                : item.grade_auth == 2
                ? "启初梦谷"
                : item.grade_auth == 3
                ? "青空天台"
                : item.grade_auth == 4
                ? "无极云顶"
                : item.grade_auth == 5
                ? "返朴归源"
                : ""
            }}及以上行者查看
          </view>
        </view>

        <!-- 赞，评论 -->
        <view class="zanPing" @click="goPage(item)">
          <view class="showWay" v-if="displayMode">{{
            item.status == 0 ? "公开" : item.status == 1 ? "粉丝" : "自己"
          }}</view>
          <view class="showWay" v-else></view>
          <view class="zan">
            <!-- 没赞没数量 -->
            <view class="zanBtn">
              <image
                class="zanImg"
                src="@/static/images/my/icon_grzxwc_six.png"
                v-if="true"
              ></image>
              <view class="zanFont" style="margin-right: 43rpx">{{
                item.like_count
              }}</view>
            </view>

            <!-- 没评论 -->
            <view class="zanBtn">
              <image
                class="zanImg"
                src="@/static/images/icon_sy_xiaoxi.png"
              ></image>
              <view class="zanFont">{{ item.comment_count }}</view>
            </view>
          </view>
        </view>
      </view>

      <!-- 评论内容 -->
      <view v-if="true">
        <reviewContent :list="item.comment2" />
        <!-- <reviewContent /> -->
      </view>
    </view>

    <!-- <view style="height:'100rpx'"></view> -->
    <view class="bottom" v-show="!flag">
      <view class="bottom_left">
        <view @click="changeClick">
          <image
            v-if="!clickableAll"
            class="item_left_click"
            src="../static/images/my/icon_grzy_quanxuan.png"
            mode=""
          ></image>
          <image
            v-else
            class="item_left_click"
            src="../static/images/my/icon_grzy_xc_xuanzhong.png"
            mode=""
          ></image>
        </view>
        <view class="bottom_left_text">全选</view>
      </view>

      <view class="bottom_right" @click="deleteFn">删除</view>
    </view>

    <view :style="{ height: '40rpx' }"></view>

    <u-modal
      :show="show"
      :title="title"
      :content="content"
      confirmColor="#55B877"
      :closeOnClickOverlay="true"
      @confirm="confirm"
      @close="close"
      @cancel="cancel"
      :showCancelButton="true"
    ></u-modal>

    <view class="empty_view" v-if="listv && listv.length == 0">
      <image
        class="item_left_clickable"
        src="../static/images/my/kong.png"
        mode=""
      ></image>
      <view v-if="from == 'history'">您还没有历史记录~</view>
      <view v-else>当前没有相关数据，请查看其他分类或功能。</view>
    </view>
  </view>
</template>

<script>
import reviewContent from "@/components/reviewContent.vue"; //评论
import progressBar from "@/pages/components/progress_bar.vue"; //录音
import storage from "@/common/storage"; // 缓存封装
export default {
  components: {
    reviewContent,
    progressBar,
  },
  props: {
    hasSound: {
      type: Number,
      default: 0, //  0没录音  1有录音
    },
    flag: {
      type: Boolean,
      default: true,
    },
    list: {
      type: Array,
      default: () => [],
    },
    moduleType: {
      type: String,
      default: "wei", //  wei 微创   gong 共创
    },
    displayMode: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: "",
    },
    from: {
      type: String,
      default: "",
    },
    showAnTitle: {
      type: Boolean,
      default: false,
    },
    my_level_id: {
      type: Number,
      default: 0, //  当前用户等级 1-5
    },
  },
  watch: {
    list: {
      deep: true, // 深度监听每一个属性值, 如果是对象可以深度监听
      immediate: true, // 进入页面后立即自动调用handler函数
      handler(newValue) {
        this.listv = newValue;
        if (this.listv) {
          for (let i = 0; i < this.listv.length; i++) {
            this.listv[i].clickable = false;
          }
        }
        // console.log("触发了这里");
        // console.log(this.listv, "newList");
      },
    },
  },
  onLoad(options) {
    // this.type = options.type;
  },
  mounted() {
    this.anTitle = storage.get("shanAn").feilidong;
  },
  data() {
    return {
      isShow: true, // 展示方式  true公开 false粉丝可见
      itemList: [{}, {}],
      src: "",
      commentValue: "",
      inputFont: "30rpx",
      clickableAll: false,
      show: false,
      title: "确认删除",
      content: "确认删除选中内容？",
      listv: [],
      anTitle: "",
    };
  },
  methods: {
    change() {},
    dianZan() {
      uni.$u.toast("点赞啦！！！");
    },
    pinglun() {
      uni.$u.toast("评论啦！！！");
    },
    toHome(user_id) {
      uni.navigateTo({
        url: `/pages/home/home?user_id=${user_id}`,
      });
    },
    goPage(item) {
      if (this.moduleType == "gong") {
        uni.navigateTo({
          url: `/pages/detail/coCreateFly?id=${item.id}&from=${this.moduleType}`,
        });
      } else {
        if (this.type == "my") {
          uni.navigateTo({
            url: `/pages/detail/flyDetail?detailType=fei&currentId=${item.id}&from=${this.moduleType}&type=my`,
          });
        } else {
          uni.navigateTo({
            url: `/pages/detail/flyDetail?detailType=fei&currentId=${item.id}&from=${this.moduleType}`,
          });
        }
      }

      // console.log(item, "飞离洞详情");
    },
    // 跳会员页面
    goMember() {
      uni.navigateTo({
        url: `/pages/member/index`,
      });
    },

    goPreview(item, file) {
      // console.log(item);
      if (item.file_type == 30) {
        // console.log(111111, item);
        uni.navigateTo({
          url: `/components/preview?type=false&vimg=${item.url}`,
        });
      } else if (item.file_type == 10) {
        // console.log(222222222, item);
        // uni.navigateTo({
        //   url: `/components/preview?type=true&img=${item.url}`,
        // });

        // console.log(file,123)

        let str = [];
        for (let i = 0; i < file.length; i++) {
          if (file[i].file_type == 10) {
            str.push(file[i].url);
          }
        }

        uni.previewImage({
          urls: str,
          current: item.url,
          longPressActions: {
            itemList: ["发送给朋友", "保存图片", "收藏"],
            success: function (data) {
              // console.log(
              //   "选中了第" +
              //     (data.tapIndex + 1) +
              //     "个按钮,第" +
              //     (data.index + 1) +
              //     "张图片"
              // );
            },
            fail: function (err) {
              // console.log(err.errMsg);
            },
          },
        });
      }
    },
    changeClick() {
      this.clickableAll = !this.clickableAll;
      if (this.clickableAll) {
        for (let i = 0; i < this.listv.length; i++) {
          this.listv[i].clickable = true;
        }
      } else {
        for (let i = 0; i < this.listv.length; i++) {
          this.listv[i].clickable = false;
        }
      }
    },
    changeClickItem(item) {
      this.$forceUpdate();
      item.clickable = !item.clickable;
      // 判断是否全选
      let all = true;
      for (let i = 0; i < this.listv.length; i++) {
        if (this.listv[i].clickable == false) {
          all = false;
        }
      }
      if (all) {
        this.clickableAll = true;
      } else {
        this.clickableAll = false;
      }
    },
    confirm() {
      // this.show = false;
      let arr = [];
      let num = 0;
      for (let i = 0; i < this.listv.length; i++) {
        if (this.listv[i].clickable == true) {
          arr.push(this.listv[i].history_id);
          num++;
        }
      }
      // console.log(arr, "数组");
      this.deletFn(arr);
    },
    close() {
      this.show = false;
    },
    cancel() {
      this.show = false;
    },
    // 删除按钮
    deleteFn() {
      let isTrue = true;
      for (let i = 0; i < this.listv.length; i++) {
        // console.log(this.listv[i].clickable);
        if (this.listv[i].clickable == true) {
          isTrue = false;
        }
      }
      if (isTrue == true) {
        uni.$u.toast("您还未选择内容");
      } else {
        this.show = true;
      }
    },
    // 删除接口
    deletFn(arr) {
      if (this.moduleType == "wei") {
        // 微创删除
        this.$http
          .historyDel_his_weichuang({ ids: arr })
          .then((res) => {
            uni.$u.toast(res.message);
            this.show = false;
            setTimeout(() => {
              this.$emit("updateDataFei");
            }, 1000);
          })
          .catch((error) => {
            uni.$u.toast(error);
          });
      } else if (this.moduleType == "gong") {
        // 共创删除
        this.$http
          .historyDel_his_gongchuang({ ids: arr })
          .then((res) => {
            uni.$u.toast(res.message);
            this.show = false;
            setTimeout(() => {
              this.$emit("updateDataGongFei");
            }, 1000);
          })
          .catch((error) => {
            uni.$u.toast(error);
          });
      }
    },
  },
};
</script>

<style scoped lang="scss">
.box_content {
  width: 100%;
  // background: rgba(39,39,39,0.5)
  .box_content1 {
    margin-top: 64rpx;
    border-radius: 16rpx;
    padding: 0 30rpx;
    box-sizing: border-box;
  }
  .title {
    display: flex;
    align-items: center;
    position: relative;
    image {
      width: 100rpx;
      height: 100rpx;
      border-radius: 50%;
    }

    .right {
      //   margin-top: 8rpx;
      margin-left: 24rpx;

      .name {
        font-size: 32rpx;
        line-height: 42rpx;
        font-family: PingFang SC-Medium, PingFang SC;
        font-weight: 400;
        color: #eeeeee;
      }

      .gangg {
        font-size: 28rpx;
        font-family: PingFang SC-Medium, PingFang SC;
        font-weight: 400;
        color: #adadad;
        margin-top: 10rpx;
      }
    }
    .click_view {
      position: absolute;
      right: 0;
      top: 0;
      margin-top: 30rpx;
      image {
        width: 40rpx;
        height: 40rpx;
      }
    }
  }

  .all_detail {
    position: relative;
    .card_content_box_preview {
      color: #eeeeee;
      padding-top: 30rpx;
      box-sizing: border-box;
      position: absolute;
      top: 0;
      background: linear-gradient(
          360deg,
          rgba(48, 53, 77, 1) 50%,
          rgba(49, 57, 79, 0) 100%
        );
      text-align: center;
      width: 100%;
      height: 100%;
    }
  }

  .Preview_style {
    width: 100%;
    height: 300rpx;
    border-radius: 16rpx;
    background: rgba(105, 113, 151, 0.7);
    margin-top: 24rpx;
    text-align: center;
    line-height: 300rpx;
    color: white;
  }

  .box_details {
    margin-top: 24rpx;
    font-size: 28rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }

  .box_details1 {
    height: 114rpx;
    overflow: hidden;
  }

  .jiugong {
    // width: 456rpx;
    margin-top: 32rpx;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;

    .jiugong_img {
      width: 222rpx;
      height: 222rpx;
      margin-right: 12rpx;
      margin-bottom: 12rpx;
      position: relative;
      .jiugong_img_mask {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(1, 1, 1, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        .video_cover_play {
          width: 80rpx;
          height: 80rpx;
          image {
            width: 80rpx;
            height: 80rpx;
          }
        }
      }
    }
    image {
      width: 222rpx;
      height: 222rpx;
    }
    .jiugong_img:nth-child(3n) {
      margin-right: 0;
    }
  }
  .jiugong1 {
    width: 400rpx;
    image {
      width: 400rpx;
    }
  }
  .jiugong4 {
    width: 460rpx;
    .jiugong_img:nth-child(3n) {
      margin-right: 12rpx;
    }
    .jiugong_img:nth-child(2n) {
      margin-right: 0;
    }
  }
  .long_img {
    // max-width: 100%;
    // height: auto;
    margin-top: 32rpx;
    image {
      width: 366rpx;
    }
  }
  .single_video {
    margin-top: 32rpx;
    width: 100%;
    position: relative;
    // video {
    //   width: 100%;
    // }
    .jiugong_img_mask {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(1, 1, 1, 0.5);
      display: flex;
      align-items: center;
      justify-content: center;
      .video_cover_play {
        width: 80rpx;
        height: 80rpx;
        image {
          width: 80rpx;
          height: 80rpx;
        }
      }
    }
  }
  .sound {
    background: rgba(39, 39, 39, 0.5);
    padding: 47rpx 29rpx;
    border-radius: 16rpx;
    margin-top: 32rpx;
  }
  .zanPing {
    display: flex;
    width: 100%;
    // height: 110rpx;
    justify-content: space-between;
    align-items: center;
    margin-top: 21rpx;
    .showWay {
      color: #adadad;
      font-size: 28rpx;
    }
    .zan {
      display: flex;

      .zanBtn {
        display: flex;
        align-items: center;

        .zanImg {
          width: 40rpx;
          height: 40rpx;
        }

        .zanFont {
          margin: 0 0 0 10rpx;
          line-height: 40rpx;
          font-size: 28rpx;
          color: #eeeeee;
        }
      }
    }
  }
  .comment {
    margin-top: 38rpx;
    .commentInput {
      background-color: rgba(39, 44, 41, 0.5);
      border-color: rgba(39, 44, 41, 0.1) !important;
      border-radius: 16rpx 16rpx 16rpx 16rpx;
    }
  }

  .bottom {
    width: 100%;
    height: 112rpx;
    background: #272727;
    position: fixed;
    bottom: 0;
    left: 0;
    padding: 16rpx 30rpx;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .bottom_left {
      display: flex;
      align-items: center;
      .item_left_click {
        width: 40rpx;
        height: 40rpx;
      }
      .bottom_left_text {
        margin-left: 16rpx;
        color: #eeeeee;
        font-size: 30rpx;
      }
    }

    .bottom_right {
      width: 250rpx;
      height: 80rpx;
      background: #ee6060;
      border-radius: 48rpx;
      text-align: center;
      line-height: 80rpx;
      font-size: 30rpx;
      color: #eeeeee;
    }
  }

  /deep/.u-modal__content__text {
    text-align: center;
  }
  .empty_view {
    margin-top: 300rpx;
    image {
      margin: 0 auto;
      width: 410rpx;
      height: 410rpx;
    }
    view {
      font-size: 30rpx;
      color: #d8d8d8;
      text-align: center;
    }
  }
}
</style>